package 算法.LeetCode91.每日打卡题目;

import java.util.*;

/**
 * @author: 谢君臣
 * @create: 2021-02-22 21:36
 * @founction: XXXX
 */
public class day22 {
    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("bpfbhmipx"));
    }

    public static int lengthOfLongestSubstring(String s) {
        HashMap<Character, Integer> hash = new HashMap<>();
        char[] array = s.toCharArray();
        int sum = 0,n = -1;
        for (int i = 0; i < array.length; i++) {
            if (hash.containsKey(array[i])){
                int m = hash.get(array[i]);
                n = Math.max(n,m);
            }
            hash.put(array[i],i);
            sum = Math.max(i-n,sum);
        }
        return sum;
    }
}
